package azcat.planner.schedule;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;


public class Schedule {
	private Calendar calendar;
	private String date;
	private int usageHours;
	private int matsPerDay;
	private HashMap<String, Integer> dayofweek = new HashMap<String, Integer>();
	
	
	public int getMatsPerDay() {
		return matsPerDay;
	}

	public void setMatsPerDay(int matsPerDay) {
		this.matsPerDay = matsPerDay;
	}

	public Schedule(String date){
		this.date = date;
		setDaysofWeek();
		setCalendar();
	}
	
	public Schedule(){
		this.calendar = Calendar.getInstance();
		setDaysofWeek();
	}
	
	private void setCalendar(){
		calendar = Calendar.getInstance();
		String []date = this.date.split("-");
		calendar.set(Integer.parseInt(date[2]), Integer.parseInt(date[1])-1, Integer.parseInt(date[0]));
		//System.out.println(saveToFileFormat());
		
	}
	public void setTheCalendar(Calendar c, int i){
		this.calendar = Calendar.getInstance();
		//System.out.println("The value of i: " + i);
		calendar.add(Calendar.YEAR, 0);
		calendar.add(Calendar.MONTH, 0);
		calendar.add(Calendar.DATE, i);
		//calendar.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH + i);
	}
	
	public boolean compareDates(Calendar c1, Calendar c2){
		SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
		
		String formatted1 = format1.format(c1.getTime());
		String formatted2 = format2.format(c2.getTime());
		//System.out.println(formatted1 + " vs " + formatted2);
		//System.out.println(formatted1.equals(formatted2));
		return formatted1.equals(formatted2);
	}
	
	
	
	public Calendar getCalendar(){
		return this.calendar;
	}
	public int getUsageHours() {
		return usageHours;
	}
	public void setUsageHours(int usageHours) {
		this.usageHours = usageHours;
	}
	public boolean compareDayOfTheWeek(String day){
		if(dayofweek.get(day) == calendar.get(Calendar.DAY_OF_WEEK)){
			return true;
		}
		return false;
	}
	private void setDaysofWeek(){
		dayofweek.put("	u", 1);
		dayofweek.put("	m", 2);
		dayofweek.put("	t", 3);
		dayofweek.put("	w", 4);
		dayofweek.put("	r", 5);
		dayofweek.put("	f", 6);
		dayofweek.put("	s", 7);

	}
	public String printWorkerDate(){
		SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM dd, yyyy");
		return sdf.format(calendar.getTime());
	}
	public String saveToFileFormat(){
		SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
		//System.out.println("#2. " +
		//System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
		return sdf.format(calendar.getTime());
	}
	public String printDate(){
		SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy");
		//System.out.println("#2. " +
		//System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
		return matsPerDay+" piezas el "+sdf.format(calendar.getTime());
		
//		System.out.println(calendar.get(Calendar.MONTH));
//		System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
	}
//	public static void main(String[] args) {
////		Schedule s = new Schedule("29-04-2014");
////		ArrayList<Schedule> list = new ArrayList<Schedule>();
////		list.add(s);
//////		s.printDate();
//////		Calendar c = Calendar.getInstance();
////		Schedule s1 = new Schedule("30-04-2014");
////		list.add(s1);
//////		s1.printDate();
////		System.out.println(list.contains(s1));//false
//	}
	
}
